impl Solution {
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
        let mut nums_sorted = nums.clone();
        nums_sorted.sort();
        for (idx, num) in nums_sorted.iter().enumerate() {
            let mut left = idx + 1;
            let mut right = nums_sorted.len() - 1;
            while left <= right {
                let mid = (left + right) / 2;
                if nums_sorted[mid] == target - num {
                    let mut idx1 = nums.iter().position(|&x| x == *num).unwrap();
                    let mut idx2 = nums.iter().rposition(|&x| x == nums_sorted[mid]).unwrap();
                    return vec![idx1 as i32, idx2 as i32];
                }
                if nums_sorted[mid] < target - num {
                    left = mid + 1;
                } else {
                    right = mid - 1;
                }
            }
        }
        return vec![];
    }
}